<template>
  <div class="wrapper" ref="wrapper">
    <div class="content">
      <slot></slot>
    </div>
  </div>
</template>

<script>
import BScroll from "better-scroll";

export default {
  name: "Scroll",
  props: {
    probeType: {
      type: Number,
      default: 0,
      run: true,
      click:true
    },
  },
  data() {
    return {
      scroll: null,
    };
  },
  mounted() {
    this.initScroll();
  },
  methods: {
    scrollTo(x, y, time = 300) {
      this.scroll.scrollTo(x, y, time);
    },
    finishPullUp() {
      this.scroll.finishPullUp();
    },
    initScroll() {
      this.$nextTick(() => {
        // 1.创建BScroll对象
        this.scroll = new BScroll(this.$refs.wrapper, {
          click: true,
          scrollY: true,
          probeType: this.probeType,
          pullUpLoad: true,
        });
        // 2.监听滚动的位置
        this.scroll.on("scroll", (position) => {
          // this.scroll.refresh();
          // console.log(position);
          // this.scroll.finishPullUp();
          //  console.log();
          this.$emit("scroll", position);
        });

        // 3.监听上拉事件
        this.scroll.on("pullingUp", () => {
          // console.log("上拉");
          // console.log(this.scroll.pullingUpOver);
          this.$emit("pullingUp");
        });
      });
    },
  },
};
</script>

<style lang="less" scoped>
.wrapper {
  width: 100%;
  height: 100%;
  overflow: hidden;
  .content {
    width: 100%;
    height: auto;
    overflow: auto;
  }
}
</style>
